define("pages/jls_cs/djcp", [
        "../../plugins/easyui/jquery-easyui-1.5.1/jquery.easyui.min",
        "../../plugins/easyui/jquery-easyui-1.5.1/easyloader",
        "../../plugins/artTemplate/artTemplate",
        "../../common/tools",
        "../../common/kss",
        "../../pages/jls_cs/djcpForm",
        "../../common/componts",
    ],
    function(require) {
        var comonts=require("../../common/componts");
        var kss=require("../../common/kss");
        var zrsdialog=require("../../pages/jls_cs/djcpForm");
        var jbxxid="djcpId";
        var hsqddjdiog = require("");
        var selectid;
        var id;
        var Select = function(){
            comonts.initSelectPage(undefined);
            comonts.initSelect(undefined,undefined,undefined);
        }
        var tableInit=function(){
            comonts.initTable(jbxxid,{
                url:"/jls_jbxx/jbxxList",
                title:'',
                fit:true,
                tools:'#djcpId',
                columns :  [
                    {
                        field: 'oid',
                        title: '序号',
                        formatter: function(value, rowData, rowIndex){
                            return '<input type="radio" name="ryRadio" id="ryRadio' + rowIndex + '" value="' + rowData.oid + '" />';
                        }},
                    {field : 'xm',title : '姓名',width : 150,sortable:'true',formatter: function(value,row,index){return '<span title='+(row.xm==null?"":row.xm)+'>'+(row.xm==null?"":row.xm)+'</span>'}},
                    {field : 'xb',title : '性别',width : 150,sortable:'true',formatter: function(value,row,index){return '<span title='+(row.bm==null?"":row.bm)+'>'+(row.bm==null?"":row.bm)+'</span>'}},
                    {field : 'cdrqString',title : '出生日期',width : 80,sortable:'true',formatter: function(value,row,index){return '<span title='+value+'>'+value+'</span>'}},
                    {field : 'rsrqString',title : '入所日期',width : 150,sortable:'true',formatter: function(value,row,index){return '<span title='+value+'>'+value+'</span>'}},
                    {field:'operate',title:'详细信息',align:'center',width : 60,/*width:$(this).width()*0.15,*/
                        formatter:function(value, row, index){
                            var str = '<a href="#" data-target="#ckPhoto" value="'+index+'" name="opera" data-toggle="modal" class="easyui-linkbutton"><img src="../../img/xq.png"></a>';
                            return str;
                            //return  '<button id="sh_add" onclick="add"  > 不通过</button>'
                        }
                    }
                ] ,
                //基本信息双击事件
                onDblClickRow:function(rowIndex, rowData){
                    $("input[name='ryRadio']")[rowIndex].checked = true;
                    $("#"+jbxxid).datagrid("selectRow", rowIndex);
                    selectid=rowData.id;
                },

                onLoadSuccess:function(data){
                    if(data.total>0){
                        $('#'+jbxxid).datagrid("selectRow", 0);
                        $("input[name='ryRadio']")[0].checked = true;
                    }

                    $("a[name='opera']").on('click',function(){
                        var jbxx = $('#'+jbxxid).datagrid("getSelected");
                        kss.initRyJbxx(jbxx);
                    });
                    $('.datagrid-pager').find('.pagination-info').css('margin-right','25px');

                },

                onLoadSuccess:function(data){
                    if(data.total>0){
                        $('#'+jbxxid).datagrid("selectRow", 0);
                        $("input[name='ryRadio']")[0].checked = true;
                    }
                    $("a[name='opera']").each(function(){
                        $(this).on('click',function () {
                            var index = $(this).attr('value');
                            var jbxx = data.rows[index];
                            kss.initJbxxxx(jbxx.gcbh,jbxx.rybh,jbxx.xm+"--详细信息");
                        });
                    });
                },

                //单击行选中取消事件
                onClickRow:function(rowIndex, rowData){
                    if(selectid!=rowData.id){
                        $("input[name='ryRadio']")[rowIndex].checked = true;
                        selectid=rowData.id;
                    }else{
                        $("#"+jbxxid).datagrid("unselectRow",rowIndex);
                        $("input[name='ryRadio']")[rowIndex].checked = false;
                        $('#'+jbxxid).datagrid('clearSelections');
                        selectid="";
                    }
                },
                onSelect:function(rowIndex, rowData){
                },
                rightmenu:function(){
                    //kss.initJbxxRightMenu(jbxxrightmenuid);
                },
            });
            //页面高度自适应
            $('#'+jbxxid).datagrid('resize',{
                height:($(window).height()-140),
            });
        }
        var findJbxx=function(){
            var xm = $("#tz_xm").text('getValue');
            $('#'+jbxxid).datagrid('clearSelections');
            $('#'+jbxxid).datagrid('load',{
                'state':'R8',
            });
        }


        var bindAction=function(){

            $("#wsbd_query").on("click",function(){
                findJbxx();
            });

            //点击弹出表单
            $("#qjls_query").on("click",function(){
                var ryxx=$('#'+jbxxid).datagrid('getSelected');
                console.log(ryxx)
                if(ryxx){
                    zrsdialog.show(ryxx)
                }else{
                    $.messager.alert("提示","请选择要办理的人员");
                }

            })

            $(window).keydown(function(event) {
                if (event.keyCode == 13) {
                    findJbxx();
                }
            });

        }

        // var tsDc = function(){
        //     var jbxx = $("#"+jbxxid).datagrid("getChecked");
        //     console.log(jbxx);
        //     if(jbxx.length!=0){
        //         hsqddjdiog.show(jbxx);
        //     }else{
        //         $.messager.alert("提示","正在加载","info");
        //     }
        // }
        //
        // $("#dcExc").on("click",function(){
        //     tsDc();
        // });
        //
        // $("#dy").click(function(){
        //     $('#dywin').window('open');
        // });

        var initView=function(){
            tableInit();
            bindAction();
            Select();
        }
        initView();
    });
